﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ZoneLine.ViewModels;

namespace ZoneLine.Views
{
    /// <summary>
    /// MaterialInfoView.xaml 的交互逻辑
    /// </summary>
    public partial class StationResultInfoView : Window
    {
        private static StationResultInfoView _view;

        private static object _lock = new object();

        private string _code;

        private bool _isAbsCode;

        public static StationResultInfoView GetView(string code, bool isAbsCode)
        {
            lock (_lock)
            {
                if (_view == null)
                {
                    _view = new StationResultInfoView(code, isAbsCode);
                }
            }
            return _view;
        }

        private StationResultInfoView(string code, bool isAbsCode)
        {
            InitializeComponent();
            _code = code;
            _isAbsCode = isAbsCode;
            this.Loaded += StationResultInfoView_Loaded;
            this.Closed += StationResultInfoView_Closed;
        }

        private void StationResultInfoView_Closed(object sender, EventArgs e)
        {
            _view = null;
        }

        private void StationResultInfoView_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = new StationResultInfoViewModel(_code, _isAbsCode);
        }
    }
}
